package com.htudata.quartz;


import java.util.HashMap;
import java.util.Map;

import com.htudata.common.enums.PageSeqEnum;
import com.htudata.core.util.operation.StringOperationUtils;
import com.htudata.home.service.IFctService;
import com.htudata.home.service.IMntEqpService;
import com.htudata.messager.service.IMessagerService;
import com.htudata.other.service.OtherShowService;
import com.htudata.websocket.endpoint.AgentServerEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

@Slf4j
@Configuration
public class QuartzConfiguration {

  @Autowired
  private OtherShowService otherShowService;
  
  @Autowired
  private IMntEqpService eqpService;
  
  @Autowired
  private IFctService fctService;
  
  @Autowired
  private IMessagerService messagerServiceimpl;
  
  @Scheduled(cron = "${getBssInfoList.cron}")
  public void getBssInfoList() {
    Map<String, String> appCodeMap = new HashMap<>();
    appCodeMap.put(PageSeqEnum.SEQ_003.getCode(), "");
    try {
      String json = this.otherShowService.getBssInfoList(true);
      if (StringOperationUtils.isValidStr2(json))
        AgentServerEndpoint.sendAll(json, appCodeMap, null);
    } catch (Exception e) {
       log.error("",e);
    } 
  }
  
  @Scheduled(cron = "${sendUserOwnMessage.cron}")
  public void sendUserOwnMessage() {
    try {
      AgentServerEndpoint.sendUserOwnMessage();
    } catch (Exception e) {
      log.error("",e);
    } 
  }
  
  @Scheduled(cron = "${selectMntEqpDataJSON.cron}")
  public void selectEqpDataJSON() {
    Map<String, String> appCodeMap = new HashMap<>();
    appCodeMap.put(PageSeqEnum.SEQ_004.getCode(), "");
    try {
      String json = this.eqpService.selectMntEqpDataJSON();
      if (StringOperationUtils.isValidStr2(json))
        AgentServerEndpoint.sendAll(json, appCodeMap, null); 
    } catch (Exception e) {
      log.error("",e);
    } 
  }
  
  @Scheduled(cron = "${selectHisExtreJSON.cron}")
  public void selectHisExtreJSON() {
    Map<String, String> appCodeMap = new HashMap<>();
    appCodeMap.put(PageSeqEnum.SEQ_004.getCode(), "");
    try {
      String json = this.eqpService.selectHisExtreJSON();
      if (StringOperationUtils.isValidStr2(json))
        AgentServerEndpoint.sendAll(json, appCodeMap, null); 
    } catch (Exception e) {
      log.error("",e);
    } 
  }
  
  @Scheduled(cron = "${selectHisExtreJSON.cron}")
  public void selectFctDataJSON() {
    Map<String, String> appCodeMap = new HashMap<>();
    appCodeMap.put(PageSeqEnum.SEQ_006.getCode(), "");
    try {
      String json = this.fctService.selectFctDataJSON(null);
      if (StringOperationUtils.isValidStr2(json))
        AgentServerEndpoint.sendAll(json, appCodeMap, null); 
    } catch (Exception e) {
      log.error("",e);
    } 
  }
  
  @Scheduled(cron = "${selectHisExtreJSON.cron}")
  public void selectMeteoPublicSatisfctJSON() {
    Map<String, String> appCodeMap = new HashMap<>();
    appCodeMap.put(PageSeqEnum.SEQ_007.getCode(), "");
    try {
      String json = this.fctService.selectMeteoPublicSatisfctJSON();
      if (StringOperationUtils.isValidStr2(json))
        AgentServerEndpoint.sendAll(json, appCodeMap, null); 
    } catch (Exception e) {
      log.error("",e);
    } 
  }
  
  @Scheduled(cron = "${selectMeteoPublicUserCommentJSON.cron}")
  public void selectMeteoPublicUserCommentJSON() {
    Map<String, String> appCodeMap = new HashMap<>();
    appCodeMap.put(PageSeqEnum.SEQ_007.getCode(), "");
    try {
      String json = this.messagerServiceimpl.selectMeteoPublicUserCommentJSON();
      if (StringOperationUtils.isValidStr2(json))
        AgentServerEndpoint.sendAll(json, appCodeMap, null); 
    } catch (Exception e) {
      log.error("",e);
    } 
  }
}
